#ifndef SETTING_H
#define SETTING_H

#include <QWidget>
#include "userinfo.h"
#include "cabinetconfig.h"
#include <QMessageBox>
#include <QProcess>
#include <QDateTime>
#include <QMap>

namespace Ui {
class Setting;
}

class Setting : public QWidget
{
    Q_OBJECT

public:
    explicit Setting(QWidget *parent = 0);
    void updateUserTable();
    ~Setting();

public slots:
    void recvCardReader(QString cardId);

signals:
    void updateCabinetInfo(QString, QString);
    void updateServerAddr(QString);
    void updateCtrlAddr(QString);
    void updateDepartName(QString);
    void reqCloseSetting();

private slots:
    void on_user_add_clicked();
    void on_user_del_clicked();
    void on_users_cellClicked(int row, int);
    void on_user_clear_clicked();
//    void on_cabinet_id_editingFinished();
//    void on_depart_name_editingFinished();
    void on_server_address_editingFinished();
    void on_ctrl_address_editingFinished();
    void on_depart_id_editingFinished();
    void on_back_clicked();
    void on_ok_clicked();

//    void on_setTime_clicked();

    void on_setTime_clicked();

private:
    Ui::Setting *ui;
    QList<UserInfo*> listUser;
    QMap<QString, QString> nameMap;
    UserInfo* curUser;
    CabinetConfig* config;

    int userIndex(QString id, QList<UserInfo *> users);
    int cardIndex(QString card, QList<UserInfo *> users);
    void selUser(int idx);
    UserInfo *checkInfo();
    void initNameMap();
    QString printMapTab(QString key, QString val);
};

#endif // SETTING_H
